// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VirtualConnection.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Usings

    using System.Reflection;

    using Org.OpenTrader.Framework.Enums;
    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The virtual Connection.
    /// </summary>
    public class VirtualConnection : Connection
    {
        #region Constants and Fields

        /// <summary>
        /// The identity.
        /// </summary>
        private static readonly Identity Identity = Identity.Create(MethodBase.GetCurrentMethod());

        /// <summary>
        /// The connected.
        /// </summary>
        private bool connected;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="VirtualConnection"/> class.
        /// </summary>
        /// <param name="layer">
        /// The layer.
        /// </param>
        public VirtualConnection(ILayer layer)
            : base(layer)
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets Status.
        /// </summary>
        public override EConnectionStatus ConnectionStatus
        {
            get
            {
                if (this.connected)
                {
                    return EConnectionStatus.Connected;
                }

                return EConnectionStatus.Disconnected;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// The connect.
        /// </summary>
        public override Status Connect()
        {
            this.RaiseConnectingEvent();
            this.connected = true;
            this.RaiseConnectedEvent();

            return Status.Success(Identity);
        }

        /// <summary>
        /// The disconnect.
        /// </summary>
        public override Status Disconnect()
        {
            this.RaiseConnectingEvent();
            this.connected = false;
            this.RaiseDisconnectedEvent();

            return Status.Success(Identity);
        }

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The to string.
        /// </returns>
        public override string ToString()
        {
            return "virtual";
        }

        #endregion
    }
}